package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.acewill.yxd.yunxundian.R;
import cn.acewill.yxd.yunxundian.model.MessageBean;

/**
 * Created by XXX on 2017/9/12.
 */

public class messageNoticeRecycleAdapter extends RecyclerView.Adapter<messageNoticeRecycleAdapter.MyViewHolder>{

    private LookCliclListener lookCliclListener;
    private Context context;
    private List<MessageBean> list;

    public messageNoticeRecycleAdapter(Context context,List<MessageBean> list,LookCliclListener lookCliclListener){
        this.context = context;
        this.list = list;
        this.lookCliclListener = lookCliclListener;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.message_warm,parent,false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        MessageBean bean=list.get(position);
        holder.msgTitle.setText(bean.getTitle());
        holder.msgContent.setText(bean.getMsg().replaceAll("<br/>","\n"));
        if (bean.getIsread()==0){
            holder.isReadOrNot.setVisibility(View.VISIBLE);
        }else{
            holder.isReadOrNot.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class MyViewHolder extends ViewHolder{
        TextView msgTitle;
        TextView msgContent;
        ImageView isReadOrNot;
        CardView msgCard;
        public MyViewHolder(View itemView) {
            super(itemView);
            msgTitle= (TextView) itemView.findViewById(R.id.msgTitle);
            msgContent= (TextView) itemView.findViewById(R.id.msgContent);
            isReadOrNot= (ImageView) itemView.findViewById(R.id.isReadOrNot);
            msgCard= (CardView) itemView.findViewById(R.id.msgCard);
            msgCard.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    lookCliclListener.lookOnclick(getLayoutPosition());
                }
            });
        }
    }

    public interface LookCliclListener{
        void lookOnclick(int position);
    }
}
